package fire.chacracter;

import java.awt.event.KeyEvent;
import java.util.ArrayList;

import fire.gui.Dialog;
import fire.pet.Pet;
import fire.pet.Skill;
import jgame.platform.JGEngine;
import jgame.platform.JREEngine;

public class Player extends Character {

	private static Player uniquePlayer;
	private boolean walk;
	private ArrayList<Skill> skill = new ArrayList<>();

	public Player(String name, double x, double y, String gfxname, double speed) {
		super(name, x, y, 9999, gfxname, speed);
		petList.add(new Pet(3, 100, 20, 34, 34, skill,"gozilla_stop"));
		
	}

	@Override
	public void move() {
		walk = false;
		if (JREEngine.getKeyStatic(KeyEvent.VK_UP)
				&& checkCollision(0, 0, -3) != 1000) {
			setGraphic("player_u");
			this.y -= speed;
			walk = true;
		}
		if (JREEngine.getKeyStatic(KeyEvent.VK_DOWN)
				&& checkCollision(0, 0, 3) != 1000) {
			setGraphic("player_d");
			this.y += speed;
			walk = true;
		}
		if (JREEngine.getKeyStatic(KeyEvent.VK_LEFT)
				&& checkCollision(0, -3, 0) != 1000) {
			setGraphic("player_l");
			this.x -= speed;
			walk = true;
		}
		if (JREEngine.getKeyStatic(KeyEvent.VK_RIGHT)
				&& checkCollision(0, 3, 0) != 1000) {
			setGraphic("player_r");
			this.x += speed;
			walk = true;
		}
		if (walk) {
			setAnimSpeed(0.3);
		} else {
			setAnimSpeed(0);
		}
	}

	public double getSpeed() {
		return speed;
	}

	public void setSpeed(double newSpeed) {
		speed = newSpeed;
	}

	public static Player createPlayer(String name, double x, double y,
			String gfxname, double speed) {
		if (uniquePlayer == null) {
			synchronized (Player.class) {
				if (uniquePlayer == null) {
					uniquePlayer = new Player(name, x, y, gfxname, speed);
				}
			}
		} else {
			uniquePlayer.setPos(x, y);
			uniquePlayer.setGraphic(gfxname);
			uniquePlayer.setSpeed(speed);
		}
		return uniquePlayer;
	}

	public static Player getPlayer() {
		if (uniquePlayer == null) {
			synchronized (Player.class) {
				if (uniquePlayer == null) {
					uniquePlayer = new Player(" ", -100, -100, "player_d", 3);
				}
			}
		}
		return uniquePlayer;
	}
}
